<?php
//
// MissionsModule.class.php
//

// Direct access protection
if( !defined( 'LIRIOPE' )) die( 'Direct access is not allowed.' );

class MissionsModule Extends LiriopeModule {

  // show()
  //
  public function show( $vars=NULL ) {
    global $module;
    $page = a::get($vars, 'page');

    // Hold the name of the custom view file if one was passed
    // look for a custom view
    if( a::get($vars, 'template')) {
      $template = a::get($vars, 'template');
      $seek = $this->_controller . '/_' . $this->_action . '-' . basename($template) . '.php';
      $customView = load::exists( $seek );
      $module->_theme = $customView;
    }

    $yaml = new Yaml(a::get($vars, 'yaml'));
    $missions = $yaml->get();
    
    $id = a::get($vars,'id');
    $data = $missions->$id;

    // allow a text file rather than YAML text
    foreach($data as $item) {
      if(isset($item->textfile)) {
        content::start();
        include($item->textfile);
        $item->text = content::end(TRUE);
      }
    }

    $module->missions = $data;
  }

}
